<template>
  <div>
    <mt-header style="font-size:18px;position: sticky;
    top: 0;"
               title="工单列表">
      <router-link to="/"
                   slot="left">
        <mt-button icon="back"></mt-button>
      </router-link>
    </mt-header>
    <ul class="container_box">
      <li>
        <div class="box box_title">
          <div class="children">
            <p>工单号</p>
          </div>
          <div class="children">
            <p>客户</p>
          </div>
          <div class="children">
            <p>概述</p>
          </div>
        </div>
      </li>
      <li v-for="(item, index) in orderList"
          :key="index">
        <div @click="toDetail(item.id)"
             class="box">
          <div class="children children_id">
            <p>{{ item.id }}</p>
            <p v-if = "item.isTimeOut == 'Y'" class='time_out_sign'>超</p>
          </div>
          <div class="children">
            <p>{{ item.clientName }}</p>
          </div>
          <div class="children">
            <p>{{ item.title }}</p>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { getSelect } from '@/api/orderListController'
export default {
  name: 'HelloWorld',
  data () {
    return {
      orderList: [],
      newUserId: this.$store.getters.userId
    }
  },
  created () {
    let userId = this.readCookie('userId')
    this.$store.commit('userIdFun', userId)
    this.getList()
  },
  watch: {
    newUserId (n, o) {
      this.newUserId = n
    }
  },
  methods: {
    toDetail (id) {
      this.$store.commit('orderDetailsIdFun', id) // 工单编号的id
      this.$router.push('/formDetails')
    },
    getList () {
      // 开发测试数据使用
      // let resInfo = JSON.parse('{"retCode":200,"msg":"查询成功！","data":[{"id":"20200407017","title":"12e12e1","createUserId":"eurmAdmin","createUserName":"内管业务管理员","statusName":"工单处理中","workOrderTypeName":"测试0417","priority":"一般","problemDesc":"","source":"微信","clientName":"测试0407","currentHandlerName":"内管业务管理员,系统管理员","createTime":"2020-04-07 16:20:30","lastUpdateTime":"2020-04-07 16:20:30","currentWorkOrderNodeId":1586225795776,"phone":"13214134343","createUserCode":"eurmAdmin","customType":"","isTimeOut":null,"customField":{"productModel":"42L6","productClass":"仪器仪表","subCallTime":1586793600000,"dutyUnit":"1","msgGrade":"C"},"businessHandlerName":null},{"id":"20200407015","title":"","createUserId":"eurmAdmin","createUserName":"内管业务管理员","statusName":"工单处理中","workOrderTypeName":"测试0417","priority":"一般","problemDesc":"","source":"","clientName":"测试0407","currentHandlerName":"内管业务管理员,系统管理员","createTime":"2020-04-07 16:15:28","lastUpdateTime":"2020-04-07 16:15:28","currentWorkOrderNodeId":1586225795776,"phone":"13214134343","createUserCode":"eurmAdmin","customType":"","isTimeOut":null,"customField":{"productModel":"","productClass":"","dutyUnit":"","msgGrade":"C"},"businessHandlerName":null}],"count":2,"url":null}')
      // this.orderList = resInfo.data
      // end

      // if (!this.newUserId) {
      //   this.newUserId = this.$store.getters.userId
      //   this.getList()
      //   return
      // }
      let params = {
        currentPage: 1, // 当前页
        pageSize: 100, // 每页数量
        userId: this.$store.getters.userId, // 当前用户
        workOrderFilterId: 5 // 点击的工单类型id
      }
      getSelect(params).then(res => {
        let data = res.data
        if (data.retCode === 200) {
          this.orderList = data.data
        }
      })
    },
    // 读取cookies
    readCookie (name) {
      var arr,
        reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
      if ((arr = document.cookie.match(reg))) {
        return unescape(arr[2])
      } else {
        return null
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.container_box {
  font-size: 14px;
}
li {
  list-style: none;
  text-align: center;
}
.box {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ecedf2;
}
.box_title {
  font-size: 14px;
  color: #333333;
  height: 50px;
  line-height: 50px;
  font-weight: bold;
  background-color: #eff0f4;
}
.box .children {
  width: 33%;
  overflow: hidden;
  padding: 10px;
}
.box_title .children {
  padding: 0;
}
.children > p {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.children_id {
  position: relative;
}
.time_out_sign {
  text-align: center;
  line-height: 18px;
  width: 18px !important;
  height: 18px;
  font-size: 12px;
  border-radius: 50%;
  color: white;
  border-bottom-left-radius: 10%;
  background-color: #f78c35;
  position: absolute;
  right: 0;
  top: 0;
}
</style>
